-- 自动补全
return {
  "hrsh7th/nvim-cmp",
  dependencies = {
    'hrsh7th/cmp-nvim-lsp',
    'hrsh7th/cmp-buffer',
    'hrsh7th/cmp-path',
    'hrsh7th/cmp-cmdline',
    'L3MON4D3/LuaSnip',
    'saadparwaiz1/cmp_luasnip',
    'rafamadriz/friendly-snippets',
    'onsails/lspkind.nvim',
  },
  config = function()
    local cmp = require('cmp')
    local luasnip = require('luasnip')
    local lspkind = require('lspkind')

    --加载代码片段集
    require("luasnip.loaders.from_vscode").lazy_load()

    cmp.setup({
      snippet = {
        expand = function(args)
          require('luasnip').lsp_expand(args.body)
        end,
      },
      mapping = {
        ['<C-n>'] = cmp.mapping.select_next_item(),
        ['<C-p>'] = cmp.mapping.select_prev_item(),
        ['<C-space>'] = cmp.mapping.complete(),
        ['<C-d>'] = cmp.mapping.scroll_docs(-4),
        ['<C-f>'] = cmp.mapping.scroll_docs(4),
        ['<CR>'] = cmp.mapping.confirm({
          behavior = cmp.ConfirmBehavior.Replace,
          select = true,
        }),
        ["<Tab>"] = cmp.mapping(function(fallback)
          if luasnip.expand_of_jumpable() then
            luasnip.expand_of_jump()
          else
            fallback()
          end
        end, { "i", "s"} ),
      },
      sources = {
        { name = 'nvim_lsp', priority = 1000, max_item_count = 15, trigger_characters = { '.', ':', '/', '@' } },
        { name = 'luasnip', proiority = 800, keyword_length = 2 },
        { name = 'buffer', priority = 500, trigger_characters = { '.', ':', '/'} },
        { name = 'path', priority = 300, trigger_characters = { '/', '.' } },
      },
      experimental = {
        ghost_text = { hl_group = "Comment" },
      },
      sync_install = false,
      auto_install = true,
      highlight = {
        enable = true,
        additional_vim_regex_highlighting = false,
      },
      completion = {
        autocomplete = {
            cmp.TriggerEvent.TextChanged,
            cmp.TriggerEvent.InsertEnter,
        },
        keyword_length = 1,
      },
      triggeringChars = { '.', ':', '/', '@', '*' }, -- 确保包含点字符
    })
  end,
}
